package cn.gwm.flink.streaming.strategy.estimatesoh;

import cn.gwm.flink.streaming.beans.estimateSoh.ConfigData;
import cn.gwm.flink.streaming.beans.estimateSoh.EstimateSohRecord;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 电池类型为LFP的ovc有效性判断策略
 * @author GW00283474
 */
public class OcvLfpStrategy implements OcvStrategy{
    /**
     * OCV非平台有效性判断,当电池类型为LFP，车端上传的内部最大（小）额定SOC 大于 ？% ，OCV非平台有效性认为有效
     */
    static  String UPLOAD_SOC_MAX = "uploadSocMax";
    /**
     * OCV非平台有效性判断,当电池类型为LFP，内部最大（小）额定SOC小于 ？% ，OCV非平台有效性认为有效
     */
    static String INSIDE_SOC_MIN="insideSocMin";
    @Override
    public void execute(EstimateSohRecord record) throws Exception{
        //最大soc是否OCV非平台有效性
        BigDecimal bmsInnerSocMax = record.getBMS_InnerSOCmax();
        BigDecimal uploadSocMax= new BigDecimal("96");
        ConfigData configData=record.configDataMap.get(UPLOAD_SOC_MAX);
        if(Objects.nonNull(configData)){
            uploadSocMax=new BigDecimal(configData.getConfigValue());
        }
        if (Objects.nonNull(bmsInnerSocMax)) {
            boolean flag = bmsInnerSocMax.compareTo(uploadSocMax) ==1 ? true : false;
            if (flag) {
                record.setPlatformValidFlagMax(true);
            }
        }
        //最小soc是否OCV非平台有效性
        BigDecimal bmsInnerSocMin = record.getBMS_InnerSOCmin();
        BigDecimal insideSocMin= new BigDecimal("8");
        ConfigData configDataMin=record.configDataMap.get(INSIDE_SOC_MIN);
        if(Objects.nonNull(configDataMin)){
            insideSocMin=new BigDecimal(configDataMin.getConfigValue());
        }
        if (Objects.nonNull(bmsInnerSocMin)) {
            boolean flag = bmsInnerSocMin.compareTo(insideSocMin) ==-1 ? true : false;
            if (flag) {
                record.setPlatformValidFlagMin(true);
            }
        }
    }
}
